package nero.yncc.com.createart.custom;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

/**
 * Created by nero on 2017/7/9.
 */

public class MyViewPager extends ViewPager {

    /**
     * @ explain:这个 ViewPager是用来解决ScrollView里面嵌套ViewPager的 内部解决法的
     * @ author：xujun on 2016/10/25 16:38
     * @ email：gdutxiaoxu@163.com
     */

        private static final String TAG = "xujun";

        int lastX = -1;
        int lastY = -1;

        public MyViewPager(Context context) {
            super(context);
        }

        public MyViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

//        @Override
//        public boolean dispatchTouchEvent(MotionEvent ev) {
//
//            int x = (int) ev.getRawX();
//            int y = (int) ev.getRawY();
//            int dealtX = 0;
//            int dealtY = 0;
//
//            switch (ev.getAction()) {
//                case MotionEvent.ACTION_DOWN:
//                    dealtX = 0;
//                    dealtY = 0;
//                    // 保证子View能够接收到Action_move事件
//                    getParent().requestDisallowInterceptTouchEvent(true);
//                    break;
//                case MotionEvent.ACTION_MOVE:
//                    dealtX += Math.abs(x - lastX);
//                    dealtY += Math.abs(y - lastY);
//                    Log.i(TAG, "dealtX:=" + dealtX);
//                    Log.i(TAG, "dealtY:=" + dealtY);
//                    // 这里是够拦截的判断依据是左右滑动，读者可根据自己的逻辑进行是否拦截
//                    if (dealtX >= dealtY) {
//                        Log.e("123","up");
//                        getParent().requestDisallowInterceptTouchEvent(true);
////                        return false;
//                    } else {
//                        Log.e("123","left");
////                        return false;
//                        getParent().requestDisallowInterceptTouchEvent(true);
//                    }
//                    lastX = x;
//                    lastY = y;
//                    break;
//                case MotionEvent.ACTION_CANCEL:
//                    break;
//                case MotionEvent.ACTION_UP:
//                    break;
//
//            }
//            return super.dispatchTouchEvent(ev);
//        }
}
